package com.zhsj.OkeHomeConsumption.ui.activity.bussiness;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hjq.bar.TitleBar;
import com.hjq.base.BaseDialog;
import com.hjq.dialog.InputDialog;
import com.hjq.dialog.MenuDialog;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.widget.SettingBar;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.internal.entity.CaptureStrategy;
import com.zhihu.matisse.listener.OnCheckedListener;
import com.zhihu.matisse.listener.OnSelectedListener;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.adapter.GridViewAddImgesAdpter;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.empty.CityLookpayeeBean;
import com.zhsj.OkeHomeConsumption.empty.CityPartnerShopBean;
import com.zhsj.OkeHomeConsumption.empty.DealListBean;
import com.zhsj.OkeHomeConsumption.empty.MerchantTypeBean;
import com.zhsj.OkeHomeConsumption.empty.RestaurantBean;
import com.zhsj.OkeHomeConsumption.empty.SelectCityEnity;
import com.zhsj.OkeHomeConsumption.empty.StoreManger;
import com.zhsj.OkeHomeConsumption.empty.StoredetailsTypeBean;
import com.zhsj.OkeHomeConsumption.empty.UpLoadImgBean;
import com.zhsj.OkeHomeConsumption.ui.activity.bussiness.mvp.BussinessMangerPresenter;
import com.zhsj.OkeHomeConsumption.ui.activity.bussiness.mvp.BussinessMangerUiinterface;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.StoredetailsTypeActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.StoredetailsPresenter;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.StoredetailsUIInterFace;
import com.zhsj.OkeHomeConsumption.ui.activity.mvp.RestaurantPresenter;
import com.zhsj.OkeHomeConsumption.utils.Glide4Engine;
import com.zhsj.OkeHomeConsumption.utils.JsonUtils;
import com.zhsj.OkeHomeConsumption.utils.SelectCityPicker;
import com.zhsj.OkeHomeConsumption.utils.UpLoadGridView;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StoreManagerActivity extends MyActivity implements View.OnClickListener, StoredetailsUIInterFace, BussinessMangerUiinterface {

    private TitleBar tb_test_a_bar;
    private AppBarLayout tb_test_store_bar;
    private List<UpLoadImgBean> imageServiceList = null;



    private UpLoadGridView store_logo;   //logo
    private GridViewAddImgesAdpter store_logo_gridViewAddImgesAdpter;
    private List<UpLoadImgBean> store_logo_imageServiceList;


    private UpLoadGridView store_pic;    //背景图
    private GridViewAddImgesAdpter dianpubeijingtu_gridViewAddImgesAdpter;
    private List<UpLoadImgBean> dianpubeijingtu_imageServiceList;


    private UpLoadGridView store_pics;   //店内图片
    private GridViewAddImgesAdpter diannei_gridViewAddImgesAdpter;;
    private List<UpLoadImgBean> diannei_imageServiceList;


    private UpLoadGridView store_zizhi;  //资质
    private GridViewAddImgesAdpter store_zizhi_gridViewAddImgesAdpter;;
    private List<UpLoadImgBean> store_zizhi_imageServiceList;

    private SettingBar store_time;       //时间
    private SettingBar store_service;    //服务
    private SettingBar store_name;       //名字
    private SettingBar store_type;       //类型
    private SettingBar store_yewu;       //业务
    private SettingBar store_product;    //产品
    private SettingBar store_city;       //城市
    private SettingBar store_address;    //地址
    private SettingBar store_tel;        //电话
    private SettingBar store_endtime;    //暂停时间
    private Button sb_citypartner_store_commit; //提交


    private ArrayList<StoreManger> storeManger=new ArrayList<>();

    //店内图 logo 背景图
    private int REQUEST_CODE_CHOOSE = -1;
    // 图片集合
    private List<File> datas_menlian = null;
    private StoredetailsPresenter minePersonPresenter;
    private BussinessMangerPresenter bussinessMangerPresenter;


    private ArrayList<MerchantTypeBean> mStoreTypeLists = null;
    private ArrayList<MerchantTypeBean> mStoreChildTypeLists = null;
    //城市选择
    private ArrayList<SelectCityEnity> mSelectCityLists = null;
    private List<StoredetailsTypeBean>  shopScopeList;//存储选中的值
    //经营类别id （用于获取主营业务）
    private int TypeId = -1;

    private int proviceId = -1;//省
    private int mcityId = -1;//市
    private int districCountryId = -1;//区
    private int streetId;//街道
    @Override
    protected int getLayoutId() {
        return R.layout.activity_store_manager;
    }
    @Override
    protected int getTitleId() {

        return R.id.tb_test_a_bar;
    }

    protected void initView() {
        minePersonPresenter = new StoredetailsPresenter(getActivity(), this);
        bussinessMangerPresenter=new BussinessMangerPresenter(getActivity(),this);
        tb_test_a_bar = (TitleBar) findViewById(R.id.tb_test_a_bar);
        tb_test_store_bar = (AppBarLayout) findViewById(R.id.tb_test_store_bar);
        store_service = (SettingBar) findViewById(R.id.store_service);
        store_name = (SettingBar) findViewById(R.id.store_name);
        store_type = (SettingBar) findViewById(R.id.store_type);
        store_yewu = (SettingBar) findViewById(R.id.store_yewu);
        store_product = (SettingBar) findViewById(R.id.store_product);
        store_city = (SettingBar) findViewById(R.id.store_city);
        store_address = (SettingBar) findViewById(R.id.store_address);
        store_zizhi = (UpLoadGridView) findViewById(R.id.store_zizhi);
        sb_citypartner_store_commit = (Button) findViewById(R.id.sb_citypartner_store_commit);
        store_tel=(SettingBar)findViewById(R.id.store_tel);
        store_logo = (UpLoadGridView) findViewById(R.id.store_logo);
        store_pic = (UpLoadGridView) findViewById(R.id.store_pic);
        store_pics = (UpLoadGridView) findViewById(R.id.store_pics);
        store_time = (SettingBar) findViewById(R.id.store_time);
        store_endtime = findViewById(R.id.store_endtime);
        store_time.setOnClickListener(this);
        tb_test_store_bar.setOnClickListener(this);
        tb_test_a_bar.setOnClickListener(this);
        store_service.setOnClickListener(this);
        store_name.setOnClickListener(this);
        store_type.setOnClickListener(this);
        store_endtime.setOnClickListener(this);
        store_yewu.setOnClickListener(this);
        store_city.setOnClickListener(this);
        store_address.setOnClickListener(this);
        sb_citypartner_store_commit.setOnClickListener(this);
        store_tel.setOnClickListener(this);
        store_product.setOnClickListener(this);
        shopScopeList = new ArrayList<>();
        diannei_imageServiceList=new ArrayList<>();
        dianpubeijingtu_imageServiceList=new ArrayList<>();
        store_logo_imageServiceList=new ArrayList<>();
        store_zizhi_imageServiceList=new ArrayList<>();
        bussinessMangerPresenter.getmangerlist(10);
    }
    @Override
    protected void initData() {

        diannei_gridViewAddImgesAdpter = new GridViewAddImgesAdpter(diannei_imageServiceList, getActivity());
        diannei_gridViewAddImgesAdpter.setMaxImages(8);
        store_pics.setAdapter(diannei_gridViewAddImgesAdpter);
        store_pics.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //店面图
                REQUEST_CODE_CHOOSE = 1;
                requestPermission(REQUEST_CODE_CHOOSE, 8);
            }
        });

        store_logo_gridViewAddImgesAdpter = new GridViewAddImgesAdpter(store_logo_imageServiceList, getActivity());
        store_logo_gridViewAddImgesAdpter.setMaxImages(2);
        store_logo.setAdapter(store_logo_gridViewAddImgesAdpter);
        store_logo.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //店铺logo
                REQUEST_CODE_CHOOSE = 2;
                requestPermission(REQUEST_CODE_CHOOSE, 1);
            }
        });


        dianpubeijingtu_gridViewAddImgesAdpter = new GridViewAddImgesAdpter(dianpubeijingtu_imageServiceList, getActivity());
        dianpubeijingtu_gridViewAddImgesAdpter.setMaxImages(2);
        store_pic.setAdapter(dianpubeijingtu_gridViewAddImgesAdpter);
        store_pic.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //店铺背景图
                REQUEST_CODE_CHOOSE = 3;
                requestPermission(REQUEST_CODE_CHOOSE, 1);
            }
        });


        store_zizhi_gridViewAddImgesAdpter = new GridViewAddImgesAdpter(dianpubeijingtu_imageServiceList, getActivity());
        store_zizhi_gridViewAddImgesAdpter.setMaxImages(2);
        store_zizhi.setAdapter(store_zizhi_gridViewAddImgesAdpter);
        store_zizhi.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //资质
                REQUEST_CODE_CHOOSE = 4;
                requestPermission(REQUEST_CODE_CHOOSE, 1);
            }
        });

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.store_name:
                InputDialog(1, "店铺名称");
                break;
            case R.id.store_tel:
                InputDialog(2, "电话号码");
                break;
            case R.id.store_address:
                InputDialog(3, "详细地址");
                break;
            case R.id.store_service:;
                InputDialog(4, "商家服务");
                break;
            case R.id.store_yewu:
                //主营业务
                minePersonPresenter.MerchantChildTypeGet(TypeId);
            case R.id.store_type:
                //经营类别
                minePersonPresenter.MerchantTypeGet();
                break;
            case R.id.store_product:
                //主营产品
                startActivityForResult(new Intent(getActivity(), StoredetailsTypeActivity.class), 5);
                break;
            case R.id.store_time:
                //营业时间
                checktimer(1);
                break;
            case R.id.store_endtime:
                checktimer(2);
                break;
            case R.id.store_city:
                minePersonPresenter.CityListPsot();
                break;
            case R.id.sb_citypartner_store_commit:
                break;


        }
    }
    /**
     * 图片选择
     */
    private void Pictureselection(int code, int max) {
        Matisse.from(StoreManagerActivity.this)
                .choose(MimeType.ofImage(), false)
                .countable(true)
                .capture(true)
                .captureStrategy(
                        new CaptureStrategy(true, "com.zhsj.OkeHomeConsumption.fileprovider"))
                .maxSelectable(max)
                .gridExpectedSize(
                        getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
                .thumbnailScale(0.85f)
                .imageEngine(new Glide4Engine())    // for glide-V4
                .setOnSelectedListener(new OnSelectedListener() {
                    @Override
                    public void onSelected(
                            @NonNull List<Uri> uriList, @NonNull List<String> pathList) {
                        // DO SOMETHING IMMEDIATELY HERE
                        Log.e("onSelected", "onSelected: pathList=" + pathList);

                    }
                })
                .showSingleMediaType(true)
                .originalEnable(true)
                .maxOriginalSize(9)
                .setOnCheckedListener(new OnCheckedListener() {
                    @Override
                    public void onCheck(boolean isChecked) {
                        // DO SOMETHING IMMEDIATELY HERE
                        Log.e("isChecked", "onCheck: isChecked=" + isChecked);
                    }
                })
                .forResult(code);
    }

    /**
     * 请求权限
     */
    private void requestPermission(final int code, final int max) {
        XXPermissions.with(getActivity())
                .constantRequest() // 可设置被拒绝后继续申请，直到用户授权或者永久拒绝
                .permission(Permission.CAMERA)
                .request(new OnPermission() {

                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        Pictureselection(code, max);
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        toast("权限请求被拒绝");
                    }
                });

    }
    /**
     * user转换为file文件
     * 返回值为file类型
     *
     * @param uri
     * @return
     */
    private File uri2File(Uri uri) {
        String img_path;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor actualimagecursor = getActivity().managedQuery(uri, proj, null,
                null, null);
        if (actualimagecursor == null) {
            img_path = uri.getPath();
        } else {
            int actual_image_column_index = actualimagecursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            actualimagecursor.moveToFirst();
            img_path = actualimagecursor
                    .getString(actual_image_column_index);
        }
        File file = new File(img_path);
        return file;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
            //图片路径 同样视频地址也是这个 根据requestCode
            List<Uri> list = Matisse.obtainResult(data);
            for (int i = 0; i < list.size(); i++) {
                datas_menlian.add(uri2File(list.get(i)));
            }
            minePersonPresenter.UploadPost(datas_menlian);
        } else if (requestCode == 5) {
            //主营产品
            shopScopeList=(ArrayList<StoredetailsTypeBean>)data.getSerializableExtra("list");
            List<String> list = new ArrayList<>();
            for(int i = 0;i<shopScopeList.size();i++){
                list.add(shopScopeList.get(i).getBusinessScopeName());
            }
            store_product.setRightText(StringUtils.strip(list.toString(),"[]"));
        }
    }
    /**
     * 多张图片上传
     */
//    @Override
    public void UploadPost(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsondata = jsonOBJ.optJSONArray("data");
                imageServiceList = new Gson().fromJson(jsondata.toString(), new
                        TypeToken<ArrayList<UpLoadImgBean>>() {
                        }.getType());
                if (imageServiceList != null && imageServiceList.size() > 0) {
                    switch (REQUEST_CODE_CHOOSE) {
                        case 1://店内图
                            for (int i = 0; i < imageServiceList.size(); i++) {
                                diannei_imageServiceList.add(imageServiceList.get(i));
                            }
                            diannei_gridViewAddImgesAdpter.notifyDataSetChanged(diannei_imageServiceList);
                            break;
                        case 2://logo
                            for (int i = 0; i < imageServiceList.size(); i++) {
                                store_logo_imageServiceList.add(imageServiceList.get(i));
                            }
                            store_logo_gridViewAddImgesAdpter.notifyDataSetChanged(store_logo_imageServiceList);
                        case 3://背景图
                            for (int i = 0; i < imageServiceList.size(); i++) {
                                dianpubeijingtu_imageServiceList.add(imageServiceList.get(i));
                            }
                            dianpubeijingtu_gridViewAddImgesAdpter.notifyDataSetChanged(dianpubeijingtu_imageServiceList);
                            break;
                        case 4:
                            for (int i = 0; i < imageServiceList.size(); i++) {
                                store_zizhi_imageServiceList.add(imageServiceList.get(i));
                            }
                            store_zizhi_gridViewAddImgesAdpter.notifyDataSetChanged(store_zizhi_imageServiceList);
                            break;
                    }
                    imageServiceList.clear();

                }
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            log("城市合伙人--- 多张图片上传");
        }
    }

    private void InputDialog(final int tag, final String title) {
        new InputDialog.Builder(this)
                .setTitle(title)
                .setCancelable(false)
                .setListener(new InputDialog.OnListener() {
                    @Override
                    public void onConfirm(Dialog dialog, String content) {
                        switch (tag) {
                            case 1:
                                if (!store_name.getRightText().equals(content)) {
                                    store_name.setRightText(content);
                                }
                                break;
                            case 2:
                                if (!store_tel.getRightText().equals(content)) {
                                    store_tel.setRightText(content);
                                }
                                break;
                            case 3:
                                if (!store_address.getRightText().equals(content)) {
                                    store_address.setRightText(content);
                                }
                                break;

                            case 4:
                                if (!store_service.getRightText().equals(content)) {
                                    store_service.setRightText(content);
                                }
                                break;
                        }
                    }
                    @Override
                    public void onCancel(Dialog dialog) {
                    }
                })
                .show();
    }

    /**
     * 时间选择器
     */
    private void checktimer(final int flage) {
        TimePickerView pvOptions = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                switch (flage) {
                    case 1:
                        store_time.setRightText(com.zhsj.OkeHomeConsumption.utils.StringUtils.formatDate2(date.toString()));
                        break;
                    case 2:
                        store_endtime.setRightText(com.zhsj.OkeHomeConsumption.utils.StringUtils.formatDate2(date.toString()));
                        break;
                }
            }
        }).setType(new boolean[]{false, false, false, true, true, false})// 默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确认")//确认按钮文字
                .setContentTextSize(18)//滚轮文字大小
                .setTitleSize(20)//标题文字大小
                .setTitleText("时间")//标题文字
                .setOutSideCancelable(false)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(true)//是否循环滚动
                .setTitleColor(Color.BLACK)//标题文字颜色
                .setSubmitColor(Color.BLACK)//确定按钮文字颜色
                .setCancelColor(Color.BLACK)//取消按钮文字颜色
                .setTitleBgColor(0xFFFFFFFF)//标题背景颜色 Night mode
                .setBgColor(0xFFFFFFFF)//滚轮背景颜色 Night mode
//                .setRangDate(startDate,endDate)//起始终止年月日设定
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(true)//是否显示为对话框样式
                .build();
        pvOptions.show();
    }

    //经营类型
    @Override
    public void MerchantTypeGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsonarr = jsonOBJ.optJSONArray("data");
                // 数据对接正常
                mStoreTypeLists = new Gson().fromJson(jsonarr.toString(), new
                        TypeToken<ArrayList<MerchantTypeBean>>() {
                        }.getType());
                List<String> datalist = new ArrayList<>();
                for (int i = 0; i < mStoreTypeLists.size(); i++) {
                    datalist.add(mStoreTypeLists.get(i).getName());
                }
                MenuDialog(datalist, 1);
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("MerchantTypeGet", "获取经营类型异常");
        }
    }

   //主营业务
    @Override
    public void MerchantChildTypeGet(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsonarr = jsonOBJ.optJSONArray("data");
                // 数据对接正常
                mStoreChildTypeLists = new Gson().fromJson(jsonarr.toString(), new
                        TypeToken<ArrayList<MerchantTypeBean>>() {
                        }.getType());

                List<String> datalist = new ArrayList<>();
                for (int i = 0; i < mStoreChildTypeLists.size(); i++) {
                    datalist.add(mStoreChildTypeLists.get(i).getName());
                }
                MenuDialog(datalist, 2);
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("MerchantChildTypeGet", "主营业务");
        }
    }

    private void MenuDialog(List<String> datalist, final int flage) {
        new MenuDialog.Builder(this)
                .setCancel("取消") // 设置 null 表示不显示取消按钮
                //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
                .setList(datalist)
                .setListener(new MenuDialog.OnListener() {

                    @Override
                    public void onSelected(Dialog dialog, int position, String text) {

                        if (flage == 1) {
                            if (!store_type.getRightText().equals(text)) {
                                store_type.setRightText(text);
                            }
                            TypeId = mStoreTypeLists.get(position).getId();
                        } else {
                            if (!store_yewu.getRightText().equals(text)) {
                                store_yewu.setRightText(text);
                            }
                        }
                    }

                    @Override
                    public void onCancel(Dialog dialog) {
                        toast("取消了");
                    }
                })
                .setGravity(Gravity.BOTTOM)
                .setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
                .show();
    }


    //所在城市
    @Override
    public void CityListPsot(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                JSONArray jsonarr = jsonOBJ.optJSONArray("data");
                // 数据对接正常
                mSelectCityLists = new Gson().fromJson(jsonarr.toString(), new
                        TypeToken<ArrayList<SelectCityEnity>>() {
                        }.getType());
                getSelectCity(mSelectCityLists);

            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            Log.e("CityListPsot", "获取城市列表");
        }
    }

    /**
     * 选择城市
     *
     * @param mSelectProviceEnities
     */
    private void getSelectCity(ArrayList<SelectCityEnity> mSelectProviceEnities) {
        SelectCityPicker selectCityPicker = new SelectCityPicker(getActivity(), mSelectProviceEnities);
        selectCityPicker.setHalfScreen(true);
        selectCityPicker.setCancelTextColor(R.color.colorAccent);
        selectCityPicker.setSubmitTextColor(R.color.colorAccent);
        selectCityPicker.setOnCitySelectListener(new SelectCityPicker.OnCitySelectListener() {
            @Override
            public void onCitySelect(String province, String city, String county, String town, int provinceId, int cityId, int countyId, int townId) {
                if (!province.equals("") && city.equals("") && county.equals("") && town.equals("")) {
                    store_city.setRightText(province);
                } else if (!province.equals("") && !city.equals("") && !county.equals("") && town.equals("")) {
                    store_city.setRightText(province);
                } else if (!province.equals("") && !city.equals("") && county.equals("") && town.equals("")) {
                    store_city.setRightText(province + "-" + city);
                } else {
                    store_city.setRightText(province + "-" + city + "-" + county + "-" + town);
                }
                proviceId = provinceId;
                mcityId = cityId;
                districCountryId = countyId;
                streetId = townId;
            }
        });
        selectCityPicker.show();
    }

    //店铺管理
    @Override
    public void Update(String context) {
        String name = store_name.getRightText().toString();
        String address = store_address.getRightText().toString();
        String tel = store_tel.getRightText().toString();
        String time = store_time.getRightText().toString();
        String service = store_service.getRightText().toString();
        String type = store_type.getRightText().toString();
        String yewu = store_yewu.getRightText().toString();
        String product = store_product.getRightText().toString();
        String city = store_city.getRightText().toString();
        String endtime = store_endtime.getRightText().toString();

//        Gson gson = new Gson();
//        Map<String, Object> mapjson = new HashMap<>();
//        mapjson.put("cityCopartnerName", name);
//        mapjson.put("del", tel);
//        mapjson.put("provinceId", proviceId);//省id
//        mapjson.put("cityId", mcityId);//市ID
//        mapjson.put("districCountryId", districCountryId);//县ID
//        mapjson.put("streetId", streetId);//街道id
//        mapjson.put("address", address);
//        String lifeCityCopartnerDTO = gson.toJson(mapjson);//map转json字符串
//        minePersonPresenter.Update(lifeCityCopartnerDTO);
    }

    @Override
    public void FindByUserIdGet(String context) {

    }


    @Override
    public void getmangerlist(String context) {
        try {
            JSONTokener jsonT = new JSONTokener(context);
            JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
            String code = jsonOBJ.optString("code");
            String message = jsonOBJ.optString("message");
            if (code.equals("N000000")) {
                // 数据对接正常
                JSONObject jsonobj = jsonOBJ.optJSONObject("data");
                StoreManger storeMangebean = JsonUtils.object(jsonobj.toString(), StoreManger.class);
                storeManger.add(storeMangebean);
                for (int i = 0; i <storeManger.size() ; i++) {
                    store_name.setRightText(storeManger.get(i).getShopName());
                    store_tel.setRightText(storeManger.get(i).getShopMobile());
                    store_city.setRightText(storeManger.get(i).getCityName());
                    store_address.setRightText(storeManger.get(i).getAddress());
                    store_type.setRightText(storeManger.get(i).getCategoryLevel1Name());
                    store_yewu.setRightText(storeManger.get(i).getCategoryLevel2Name());
                    store_product.setRightText(storeManger.get(i).getShopBusinessScopeText());
                }
            } else if (code.equals(Constants.STATUSTOKENERROR)) {
                // token过期
                if (!message.equals("null")) {
                    toast(message);
                }
            } else {
                if (!message.equals("null")) {
                    toast(message);
                }
            }
        } catch (JSONException ex) {
            log("获取店铺管理数据异常");
        }
    }


}
